import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import Particles from 'particles.vue3'
import Avue from '@smallwei/avue';
import '@smallwei/avue/lib/index.css';
import './mock'
import VConsole from 'vconsole'


console.log(import.meta.env);



if(import.meta.env.VITE_APP_ENV == 'test'){
  const vConsole = new VConsole()
}

const app = createApp(App)
app.use(Particles)
app.use(createPinia())
app.use(router)
app.use(ElementPlus)
app.use(Avue);
app.mount('#app')


// 全局定义自定义指令 单机复制  v-copy
app.directive("copy", {
  mounted(el, info, Vnode) {
    // console.log(el, info, Vnode);
    el.addEventListener("click", () => {
      let texts = document.createElement("textarea");
      el.parentNode.appendChild(texts);
      texts.value = el.innerHTML;
      texts.select();
      let flage = document.execCommand("Copy");
      if (flage) {
        texts.remove();
      }
    });
  },
});
// 全局定义自定义指令 添加水印 v-waterMarker
app.directive("waterMarker", {
  created(el, info, Vnode) {
    console.log(info);
    var can = document.createElement("canvas");
    el.appendChild(can);
    can.width = 200;
    can.height = 150;
    can.style.display = "none";
    var cans = can.getContext("2d");
    cans.rotate((-20 * Math.PI) / 180);
    cans.font = "16px Microsoft JhengHei";
    cans.fillStyle = "rgba(180, 180, 180, 0.3)";
    cans.textAlign = "left";
    cans.textBaseline = "Middle";
    cans.fillText(info.value, can.width / 10, can.height / 2);
    el.style.backgroundImage = "url(" + can.toDataURL("image/png") + ")";
  },
});

